#include "Http_Get_Time.h"

/*宏定义*/
#define HTTP_HOST "quan.suning.com"
#define HTTP_PORT 80
#define URL "/getSysTime.do"

/*静态全局变量*/
static HTTPClient http;

/*全局变量*/
uint8_t hour = 0;//小时
uint8_t minute = 0;//分钟

uint8_t month = 0;//月
uint8_t day = 0;//日

uint8_t get_time_flag = 0;//获取时间标志位 0--没有获取成功 1--获取成功


/*全局函数*/
void Http_Get_Time(void)
{
    if(Get_Wifi_State())
    {
        http.begin(HTTP_HOST, HTTP_PORT, URL);
        int httpret = http.GET();
        if(httpret > 0)
        {
            String response = http.getString();
            month = response.substring(18, 20).toInt();
            day = response.substring(21, 23).toInt();

            hour = response.substring(24, 26).toInt();
            minute = response.substring(27, 29).toInt();

            Serial.printf("%d %d %d %d\r\n", month, day, hour, minute);

            get_time_flag = 1;
            //Serial.println(response);
            //Serial.println(response);
        }
        else
        {
            Serial.println("no time get");
            get_time_flag = 0;
        }
    }
    else
    {

    }
}
